main(n,i,o,j,b){
	char a[99];
	for(gets(a);gets(a);)
	{
		n=o=i=0;
		i+=*a&2?4:3;
		a[i-1]=0;
		for(j=6,b=7;j--;b+=a[b]&2?4:3)
			a[b]&2?o++:n++;
		if(*a==a[i])puts(a);
		else
			puts(n!=o?n>o?"IN":"OUT":"AGAIN");
	}
}
